package cn.com.dycc.util;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import cn.com.dycc.party_org.organize.entity.PartyInfo;
/**
 * 党组织显示树
 * @author Administrator
 *
 */
public class OrganiTreeUtil {
	
	
	public static Map<String,Object> mapArray = new LinkedHashMap<String, Object>();
	public List<PartyInfo> PartyInfoCommon; 
	public List<Object> list = new ArrayList<Object>(); 
	
	//树状排序
	public List<Object> PartyList(List<PartyInfo> listPartyInfo){ 
		this.PartyInfoCommon = listPartyInfo;
		for(PartyInfo x : listPartyInfo){
			Map<String,Object> mapArr = new LinkedHashMap<String, Object>();
			if("0".equals(x.getPid())){
				mapArr.put("id",x.getDept_id());
				mapArr.put("name",x.getDept_name());
				mapArr.put("pid",x.getPid());
//				mapArr.put("pid",x.getPid());
				mapArr.put("open","true");
				//子部门
				mapArr.put("children",children(x.getDept_id()));
				list.add(mapArr);
			}
		}
		return list;
	}
	
	 public List<?> children(String deptNo){
		 List<Object> lists = new ArrayList<Object>();
		 for(PartyInfo a:PartyInfoCommon){
			 Map<String,Object> childArray = new LinkedHashMap<String, Object>();
			 if(deptNo.equals(a.getPid())){
				 childArray.put("id",a.getDept_id());
				 childArray.put("name",a.getDept_name());
				 childArray.put("pid",a.getPid());
//				 childArray.put("pid",a.getPid());
				 childArray.put("open","true");
				//子部门
				 childArray.put("children",children(a.getDept_id())); 
				 lists.add(childArray);
			 }
		 }
		 return lists;
	 }
	 
	//平行排序 
	public List<Object> PartyLine(List<PartyInfo> listPartyInfo){ 
		this.PartyInfoCommon = listPartyInfo;
		for(PartyInfo x : listPartyInfo){
			Map<String,Object> mapArr = new LinkedHashMap<String, Object>();
			if("0".equals(x.getPid())){
				mapArr.put("id",x.getDept_id());
				mapArr.put("name",x.getDept_name());
				mapArr.put("pid",x.getPid());
//					mapArr.put("pid",x.getPid());
				mapArr.put("open","true");
				list.add(mapArr);
				//启动子
				children(x.getDept_id());
			}
		}
		return list;
	}
		
	 public List<?> childrenLine(String deptNo){
//		 List<Object> lists = new ArrayList<Object>();
		 for(PartyInfo a:PartyInfoCommon){
			 Map<String,Object> childArray = new LinkedHashMap<String, Object>();
			 if(deptNo.equals(a.getPid())){
				 childArray.put("id",a.getDept_id());
				 childArray.put("name",a.getDept_name());
				 childArray.put("pid",a.getPid());
//					 childArray.put("pid",a.getPid());
				 childArray.put("open","true");
				 list.add(childArray);
				 children(a.getDept_id());
			 }
		 }
		 return list;
	 }
}
